package com.commerce.reader.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.commerce.reader.Entity.Book;
import com.commerce.reader.Entity.Books;
import com.commerce.reader.Entity.Chapter;

import java.util.List;


public class MyListAdapter extends BaseAdapter {

    Context context; List<Chapter> map;

    public MyListAdapter(Context context, List<Chapter> map) {
        this.context=context;
        this.map= map;
    }

    @Override
    public int getCount() {
        return map.size();
    }

    @Override
    public Object getItem(int i) {
        return map.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    private class ViewHolder{
        private TextView text1;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
         if(view==null){
            view = LayoutInflater.from(context).inflate(android.R.layout.simple_dropdown_item_1line,null);
            viewHolder = new ViewHolder();
            viewHolder.text1=view.findViewById(android.R.id.text1);
            view.setTag(viewHolder);
         }else {
            viewHolder= (ViewHolder) view.getTag();
         }
        Log.d("TAG", "getView: " +"++++++" + "-------" + "-------"+ i);
        viewHolder.text1.setText(map.get(i).getChapter());
        return view;
    }
}
